<?php

/**
 * 邮件模板设置
 */
if (!defined('IN_DIALOG'))
    die("Access Denied");

$emaillist = array();
$id = isset($_GET['id']) ? (int) $_GET['id'] : 0;


if ($id) {
    if (Utils::submitCheck('emailsubmit')) {
        $subject = $_POST['subject'];
        $content = $_POST['content'];
        $setarr = array('subject' => $subject,
            'content' => $content);
        $result = $_SGLOBAL['db']->updateTable('emailtemplate', $setarr,array('id'=>$id));
        if ($result) {
            Config::updateConfig('email');
            Utils::showMessage('do_success');
        }else{
            Utils::showMessage('do_error');
        }
    } else {
        $email = $_SGLOBAL['db']->getOne('emailtemplate', array('id' => $id));
        $_SGLOBAL['view']->assign('email', $email);
    }
} else {
    $query = $_SGLOBAL['db']->query("SELECT id,type,title FROM " . Utils::tname('emailtemplate'));
    while ($row = $_SGLOBAL['db']->fetchArray($query)) {
        $emaillist[] = $row;
    }
}
$_SGLOBAL['view']->assign('emaillist', $emaillist);
$_SGLOBAL['view']->display('setup_email');
?>
